<?php
 function microtime_float()
{
		list($usec, $sec) = explode(" ", microtime());
		return ((float)$usec + (float)$sec);
}
$url=$_GET["host"]; 
$u=parse_url($url);
$port=$u['port']; 
$host=gethostbyname($u["host"]);
$scheme=$u["scheme"];
// 设置一些基本的变量
if($port==""&&$scheme==="https"){
	$port=443;
}else if($port==""&&$scheme=="http"){
	$port=80;
}
// 设置超时时间
set_time_limit(20);
// 创建一个Socket
$commonProtocol = getprotobyname("tcp");
$socket = socket_create(AF_INET, SOCK_STREAM, $commonProtocol);
//绑定Socket到端口
$time_start =microtime_float();
$result = socket_connect($socket, $host, $port);
$time_end = microtime_float();
$time = $time_end - $time_start;
$time = ceil($time * 1000);
if($result){
	echo '{"code":"1","times":"'.$time.'","httpcode":"200"}';
}else{
	echo '{"code":"0","times":"'.$time.'","httpcode":"0"}';
}
?>